# coding = utf-8
# File date: Hi_2022/1/3 11:29
# File_name: MyBalloon.py
"""tix的balloon不实用,自己写了一个"""
from tkinter import Label


class My_Balloon:
    def __init__(self, master, widget, msg, fg="black", bg="SkyBlue"):
        """"入参master, widget, msg, fg="black", bg="SkyBlue
        前景色和背景色可有可无，往后可以增加字体自定义"""
        self.balloon = Label(master, text=msg, fg=fg, bg=bg)

        # 进入控件区域
        widget.bind('<Enter>', self.balloon_shwo)
        # 离开控件区域
        widget.bind('<Leave>', self.balloon_destroy)

    def balloon_shwo(self, event):
        """显示label,暂时不考虑超出界限的问题"""
        self.balloon.place(x=event.x_root // 3, y=event.y_root // 2, anchor="center")

    def balloon_destroy(self, event):
        self.balloon.place_forget()
